home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / qic02_11.zip / MT.C < prev    next >
Text File  |  1993-04-28  |  5KB  |  182 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. char copyright[] =
  9. "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  10.  All rights reserved.\n";
  11. #endif not lint
  12.  
  13. #ifndef lint
  14. static char sccsid[] = "@(#)mt.c        5.1 (Berkeley) 4/30/85";
  15. #endif not lint
  16.  
  17. /*
  18.  * mt --
  19.  *   magnetic tape manipulation program
  20.  *
  21.  *   modified for use with DOS Archive QIC02 device driver by
  22.  *   Eddy Olk, eddy@duteca.et.tudelft.nl
  23.  *
  24.  */
  25. #include <stdio.h>
  26. #include <ctype.h>
  27. #include <sys/types.h>
  28. #include "mtio.h"
  29.  
  30. #include <io.h>
  31.  
  32. #define equal(s1,s2)    (strcmp(s1, s2) == 0)
  33.  
  34. struct commands {
  35.         char *c_name;
  36.         int c_code;
  37.         int c_ronly;
  38. } com[] = {
  39.         { "weof",       MTWEOF, 0 },
  40.         { "eof",        MTWEOF, 0 },
  41.         { "fsf",        MTFSF,  1 },
  42.         { "bsf",        MTBSF,  1 },
  43.         { "fsr",        MTFSR,  1 },
  44.         { "bsr",        MTBSR,  1 },
  45.         { "rewind",     MTREW,  1 },
  46.         { "offline",    MTOFFL, 1 },
  47.         { "rewoffl",    MTOFFL, 1 },
  48.         { "status",     MTNOP,  1 },
  49.         { "eod",        MTEOD,  1 },
  50.         { "eom",        MTEOD,  1 },
  51.         { "erase",      MTERASE,0},
  52.         { "retension",  MTRETENSION,1},
  53.         { "reset",      MTRESET, 1},
  54.         { 0 }
  55. };
  56.  
  57. int mtfd;
  58. struct mtop mt_com;
  59. struct mtget mt_status;
  60. char *tape;
  61. char *progname;
  62.  
  63. main(argc, argv)
  64.         char **argv;
  65. {
  66.         char line[80], *getenv();
  67.         register char *cp;
  68.         register struct commands *comp;
  69.  
  70.         progname = argv[0];
  71.  
  72.         if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) {
  73.                 argc -= 2;
  74.                 tape = argv[2];
  75.                 argv += 2;
  76.         } else
  77.                 if ((tape = getenv("TAPE")) == NULL)
  78.                         tape = DEFTAPE;
  79.         if (argc < 2) {
  80.                 fprintf(stderr, "usage: %s [ -f device ] command [ count ]\n",progname);
  81.                 exit(1);
  82.         }
  83.         cp = argv[1];
  84.         for (comp = com; comp->c_name != NULL; comp++)
  85.                 if (strncmp(cp, comp->c_name, strlen(cp)) == 0)
  86.                         break;
  87.         if (comp->c_name == NULL) {
  88.                 fprintf(stderr, "%s: don't grok \"%s\"\n",progname, cp);
  89.                 exit(1);
  90.         }
  91.         if ((mtfd = open(tape, comp->c_ronly ? 0 : 2)) < 0) {
  92.                 perror(tape);
  93.                 exit(1);
  94.         }
  95.         if (comp->c_code != MTNOP) {
  96.                 mt_com.mt_op = comp->c_code;
  97.                 mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1);
  98.                 if (mt_com.mt_count < 0) {
  99.                         fprintf(stderr, "%s: negative repeat count\n",progname);
  100.                         exit(1);
  101.                 }
  102.                 if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) {
  103.                         fprintf(stderr, "%s %s %d ", tape, comp->c_name,
  104.                                 mt_com.mt_count);
  105.                         perror("failed");
  106.                         exit(2);
  107.                 }
  108.         } else {
  109.                 if (ioctl(mtfd, MTIOCGET, (char *)&mt_status) < 0) {
  110.                         perror("mt");
  111.                         exit(2);
  112.                 }
  113.                 status(&mt_status);
  114.         }
  115. }
  116.  
  117.  
  118. /*
  119.  * Interpret the status buffer returned
  120.  */
  121.  
  122. typedef struct {
  123.   int mask;
  124.   char *expln;
  125. } info;
  126.  
  127. info err_byte0[] = {
  128.   { MT_FIL, "File mark detected" },
  129.   { MT_BNL, "Block not located" },
  130.   { MT_UDE, "Unrecoverable data error" },
  131.   { MT_EOM, "End of medium" },
  132.   { MT_WRP, "Write protected cartridge" },
  133.   { MT_DFF, "Device fault or SELF TEST failed" },
  134.   { MT_CNI, "Cartridge not in place" }
  135. };
  136.  
  137. info err_byte1[] = {
  138.   { MT_POR, "Power on or RESET occurred" },
  139.   { MT_EOD, "End of recorded data" },
  140.   { MT_PAR, "Bus parity error" },
  141.   { MT_BOM, "Beginning of medium" },
  142.   { MT_MBD, "Marginal block detected" },
  143.   { MT_NDT, "No data detected" },
  144.   { MT_ILL, "Illegal command" }
  145. };
  146.  
  147.  
  148. status(bp)
  149.         register struct mtget *bp;
  150. {
  151.   register int i, status;
  152.  
  153.   status = bp->mt_dsreg;
  154.   switch (bp->mt_type) {
  155.   case MT_ISAR:
  156.     printf("Archive SC402/499R QIC02");
  157.     break;
  158.   default:
  159.     printf("Unknown tape drive");
  160.   }
  161.   printf(", residual = %d\nsense (0x%04x):",
  162.          bp->mt_resid, status);
  163.  
  164.   if (!(status&MT_ST0) && !(status&MT_ST1)) {
  165.      printf("\n\tnothing special");
  166.   }
  167.   else {
  168.     if (status&MT_ST1) {
  169.        for (i=0; i<7; i++)
  170.          if (status&err_byte1[i].mask)
  171.            printf("\n\t%s", err_byte1[i].expln);
  172.      }
  173.      if (status&MT_ST0) {
  174.        for (i=0; i<7; i++)
  175.          if (status&err_byte0[i].mask)
  176.            printf("\n\t%s", err_byte0[i].expln);
  177.      }
  178.   }
  179.   printf("\nerrors = %u\nunderruns = %u\nfileno = %lu\nblockno = %lu\n",
  180.          bp->mt_erreg, bp->mt_unrun, bp->mt_fileno, bp->mt_blkno);
  181. }
  182.